package com.xuetang9.fujian.net.request;

import com.xuetang9.fujian.dao.UserDao;
import com.xuetang9.fujian.model.User;
import com.xuetang9.fujian.net.server.ECQServer;
import com.xuetang9.fujian.net.server.SocketHandler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

/**
 * @describe:
 * @author:fujian
 * @date:2021/6/13
 * @Version: V1.0
 * @Package: com.xuetang9.fujian.net.request
 */
@SuppressWarnings("all")
public class LoadRelationRequestHandler extends AbstractRequestHandler{
    private UserDao dao = new UserDao();
    @Override
    public void handleRequest(HashMap<String, Object> message, SocketHandler handler, ECQServer server) {
        String account = message.get("account").toString();
        User user = dao.get(account);
        Collection<List<String>> values = user.getGroups().values();
        List<User> relationPersons = new ArrayList<>();
        for (List<String> value : values) {
            for (String relationAccount : value) {
                relationPersons.add(dao.get(relationAccount));
            }
        }
        HashMap<String, Object> reponseMessage = new HashMap<>();
        reponseMessage.put("success",true);
        reponseMessage.put("group",user.getGroups());
        reponseMessage.put("handlerClass","");
        reponseMessage.put("relationPersons",relationPersons);
        handler.sendMessage(reponseMessage);
    }
}
